﻿/* Write a method ReadNumber(int start, int end) that enters an integer number in given range [start…end]. If an invalid number or non-number text is entered, the method should throw an exception. Using this method write a program that enters 10 numbers:
			a1, a2, … a10, such that 1 < a1 < … < a10 < 100
*/
using System;

namespace _2.ReadNumber_Integer
{
    class ReadNumber_Integer
    {
        static void Main()
        {
            int previousN = 1;
            int[] arrnums = new int[11];
            for (int i = 1; i <= 10; i++)
            {
                previousN = ReadNumber(previousN, 100);
                arrnums[i] = previousN;
                //Console.WriteLine(previousN);
            }
            Console.WriteLine("Numbers entered: (1 < a1 < a2 < a3 < ... < 100: \r\n{0}", string.Join(",", arrnums));
        }

        private static int ReadNumber(int start, int end)
        {
            int N;
            try
            {
                N = Int32.Parse(Console.ReadLine());
            }
            catch (FormatException FE)
            {
                throw new FormatException(string.Format("Error: invalid user input passed to the ReadNumber function. \r\nDebug message: {0}", FE.Message));
            }
            catch (OverflowException OE)
            {
                throw new FormatException(string.Format("Error: invalid user input passed or overflow exception detected. \r\nDebug message: {0}", OE.Message));
            }
            if (N < start || N > end)
            {
                throw new ArgumentException(string.Format("Error: invalid argument passed. The number should be between {0} and {1} with the parameters with which the function is currently called", start, end));
            }
            return N;
        }
    }
}
